const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
  entry: {
    index: './src/background.js', // 主进程入口
    preload: './src/preload.js' // 预加载脚本入口
  },
  output: {
    filename: '[name].js',
    path: path.resolve(__dirname, '.webpack/main'),
    libraryTarget: 'commonjs2'
  },
  module: {
    rules: [
      // 添加你需要的规则
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      }
    ]
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
      'three': path.resolve(__dirname, 'node_modules/three')
    },
    extensions: ['.js', '.vue', '.json']
  },
  plugins: [
    new CopyWebpackPlugin({
      patterns: [
        { from: 'src/protos', to: 'protos' }
      ]
    })
  ]
};